<?php
$articles = $this->articles;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quản lý bài viết</title>

<script
	src="<?php echo $this->baseUrl();?>/jquery/jqueryui/jquery-1.6.4.min.js"></script>

<!-- Add sự kiện cho button -->
<script type="text/javascript">
        //Write your code when Document is loaded
        $(document).ready(function() {
        	var hiddenField = document.getElementById('ListCheckboxChecked');
 

            $("#bDelete").click(function() {
            	if(confirm('Bạn có chắc muốn xóa những bài viết này ?'))
            	{
                    $("#checklist :checked").each(function() {
                        hiddenField.value += $(this).val()+',';
                    });
                    $("#pressed-id").val("bDelete");
                    $("#myform").attr("action", "manager");
                    $("#myform").submit();
                    
            	}
            });

            $("#bNew").click(function() {
                $("#pressed-id").val("bNew");
                $("#myform").attr("action", "manager");
                $("#myform").submit();
            });

            //Event for check all checkbox
            $('#checkall').click(
               function()
               {
                  $("INPUT[type='checkbox']").attr('checked', $('#checkall').is(':checked'));   
               }
            );
       });
    	</script>

</head>
<body>
<h1>Article manager</h1>

<form method="post" id="myform">

<div>
    <input type="button" id="bNew" value="New" /> 
    <input type="button" id="bDelete" value="Delete" />
</div>

<div id="checklist">
<table width="100%" border="1">
    <tr>
        <td><input type="checkbox" id="checkall" name="checkAll"
                value="checkAll"/></td>
        <td><b>Tiêu đề</b></td>
        <td><b>Chuyên mục</b></td>
        <td><b>Tạo bởi</b></td>
        <td><b>Ngày tạo</b></td>
        <td><b>Mã</b></td>
    </tr>
    <?php 
    foreach ($articles as $article)
    {
            $ID = $article['ID'];
            echo '<tr>';
            echo 	"<td><input type=\"checkbox\" name=\"$ID\" value=\"$ID\"></td>";
            echo	"<td width=\"300px\"><a href=\"show?id=$ID&view-mode=admin\">{$article['Title']}</a></td>";
            echo	"<td>{$article['CategoryName']}</td>";
            echo	"<td></td>";
            echo	"<td>{$article['CreatedTime']}</td>";
            echo	"<td>{$article['ID']}</td>";
            echo '</tr>';
    }
    ?>
	
</table>
<input type="hidden" id="ListCheckboxChecked" name="ListCheckboxChecked" />
<input type="hidden" id="pressed-id" name="pressed-id" />
</div>
</form>
</body>
</html>